
/*********************/
/**   当事人选择框   **/
/*********************/
	Ext.onReady(function(){
	 var store8 = new Ext.data.JsonStore({
	        root: 'topics',
	        totalProperty: 'totalCount',
	        idProperty: 'id',
	        remoteSort: true,
	        url: '/app/sys/usermanage/user!getUsers',
	        fields: ['id', 'name','deptName','dutyName']
	    });

	    var store28 = new Ext.data.JsonStore({
	        fields : ['name','deptName'],
			root   : 'topics'
	    });

	    var grid8 = new Ext.grid.GridPanel({
	        width:450,
	        height:250,
	        ddGroup          : 'secondGridDDGroup8',
	        enableDragDrop   : true,
	        store: store8,
	        trackMouseOver:true,
	        disableSelection:false,
	        loadMask: true,
	        stripeRows: true,
	        autoExpandColumn:'name',
	        // grid columns
	        columns:[{
	            header: "id",
	            dataIndex: 'id',
	            width: 100,
	            hidden:true
	        },{
	        	id:'name',
	            header: $("#acceptedNames8").attr("title"),
	            dataIndex: 'name',
	            width: 100
	        },{
	            header: "部门",
	            dataIndex: 'deptName',
	            width: 100
	        },{
	            header: "职务",
	            dataIndex: 'dutyName',
	            width: 100
	        }],

	        // customize view config
	        viewConfig: {
	            forceFit:false,
	            enableRowBody:true,
	            showPreview:true,
	            getRowClass : function(record, rowIndex, p, store8){
	                if(this.showPreview){
	                    return 'x-grid3-row-expanded';
	                }
	                return 'x-grid3-row-collapsed';
	            }
	        },
	        tbar: new Ext.Toolbar({
	        	items   : [
		            {
		            	xtype:'tbtext',
		                text: $("#acceptedNames8").attr("title")
		            },
		            {
		            	id:'showName8',
		                xtype:'textfield',
		                width:'100'
		            },
		            {
		            	xtype:'button',
		                text: '查询',
		                handler:function(){
		                	store8.load({params:{
		                	start:0, 
		                	limit:10,
		                	filter_LIKES_showName:$("#showName8").val()
		                	}});
		                }
		            }
		        ]
	        }),

	        // paging bar on the bottom
	        bbar: new Ext.PagingToolbar({
	            pageSize: 10,
	            store: store8,
	            displayInfo: true,
	            displayMsg: '当前显示数据 {0} - {1} of {2}',
	            emptyMsg: "没有数据可以显示"
	        })
	    });

	    var grid28 = new Ext.grid.GridPanel({
	        width:250,
	        height:250,
	        ddGroup          : 'firstGridDDGroup8',
	        enableDragDrop   : true,
	        store: store28,
	        trackMouseOver:true,
	        disableSelection:false,
	        loadMask: true,
	        stripeRows: true,
	        // grid columns
	        columns:[{
	            header: "id",
	            dataIndex: 'id',
	            width: 100,
	            hidden:true
	        },{
	            header: $("#acceptedNames8").attr("title"),
	            dataIndex: 'name',
	            width: 100
	        },{
	            header: "部门",
	            dataIndex: 'deptName',
	            width: 100
	        }],

	        // customize view config
	        viewConfig: {
	            forceFit:true,
	            enableRowBody:true,
	            showPreview:true,
	            getRowClass : function(record, rowIndex, p, store){
	                if(this.showPreview){
	                    return 'x-grid3-row-expanded';
	                }
	                return 'x-grid3-row-collapsed';
	            }
	        }
	    });
	    
   var win8 = null;
   var inputbox8 = Ext.get('acceptedNames8');
   inputbox8.on('click', function(){
       if(win8 == null){
           win8 = new Ext.Window({
               applyTo:'chooseUser8',
               title:'选择'+$("#acceptedNames8").attr("title"),
               layout:'hbox',
               width:670,
               height:320,
               closable:false,
			   modal :'true',
               plain: true,
               items:[grid8,grid28],
               buttons: [{
                   text:'选择',
                   handler: function(){
                   		var c = grid28.getStore().getCount();
                   		if(c==0){
                   			Ext.MessageBox.show({
					           title: '提示',
					           msg: '请选择'+$("#acceptedNames8").attr("title")+'！',
					           buttons: Ext.MessageBox.OK,
					           icon: Ext.MessageBox.WARNING
					       });
					       return ;
                   		}
                   		var names = "";
                   		var ids = "";
                   		for(i=0;i<c;i++){
                   			names += grid28.getStore().getAt(i).data['name']+",";
                   			ids   += grid28.getStore().getAt(i).data['id']+",";
                   		}
                   		names = names.substring(0,names.length-1);
                   		ids = ids.substring(0,ids.length-1);
                   		//alert(names+"||"+ids);
                   		$("#acceptedNames8").val(names);
                   		$("#acceptedIds8").val(ids);
                   		win8.hide();
              		}
               },{
                   text: '关闭',
                   handler: function(){
                       win8.hide();
                      // $('#hello-win').html("");
                       //win = null;
                   }
               }]
           });
       }
       win8.show(this);
       var firstGridDropTargetEl8 =  grid8.getView().scroller.dom;
       var firstGridDropTarget8 = new Ext.dd.DropTarget(firstGridDropTargetEl8, {
               ddGroup    : 'firstGridDDGroup8',
               notifyDrop : function(ddSource, e, data){
                       var records =  ddSource.dragData.selections;
                       Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
                       grid.store.add(records);
                       return true
               }
       });


       // This will make sure we only drop to the view scroller element
       var secondGridDropTargetEl8 = grid28.getView().scroller.dom;
       var secondGridDropTarget8 = new Ext.dd.DropTarget(secondGridDropTargetEl8, {
               ddGroup    : 'secondGridDDGroup8',
               notifyDrop : function(ddSource, e, data){
                       var records =  ddSource.dragData.selections;
                       Ext.each(records, ddSource.grid.store.remove, ddSource.grid.store);
                       grid28.store.add(records);
                       return true
               }
       });
       store8.load({params:{start:0, limit:10}});
       //store2.removeAll();
   });
   
 
});